//1275. 找出井字棋的获胜者
//思路：代码的注释为注意点

#include <vector>
#include <string>
using namespace std;

class Solution {
public:
    bool judge(vector<vector<int>>& board)
    {
        for(int i = 0; i < 3; i++)
        {
            if(board[i][0] == board[i][1]
            && board[i][1] == board[i][2]
            && board[i][0] != -1)
                return true;

            if(board[0][i] == board[1][i]
            && board[1][i] == board[2][i]
            && board[0][i] != -1)
                return true;
        }
        if(board[0][0] == board[1][1]
        && board[1][1] == board[2][2]
        && board[0][0] != -1)
            return true;
        if(board[0][2] == board[1][1]
        && board[1][1] == board[2][0]
        && board[0][2] != -1)
            return true;

        return false;
    }
    string tictactoe(vector<vector<int>>& moves) {
        vector<vector<int>> board(3, vector<int>(3, -1));
        for(int i = 0; i < moves.size(); i++)
        {
            int row = moves[i][0], col = moves[i][1];
            if(i % 2 == 0) 
                board[row][col] = 1;
            else
                board[row][col] = 0;

            if(i >= 4 && judge(board))//i == 4就是第五次下棋了，A就存在赢的概率，此时需要判断
                return i % 2 == 0 ? "A" : "B";//巧妙运用三目，如果是第偶数个数组，那么就是A胜利
        }
        
        //如果没有判断出AB哪个胜利，moves数组大小如果是9那么就是平局，不是就继续
        return moves.size() == 9 ? "Draw" : "Pending";
    }
};
